#ifndef __SDCARD_H
#define __SDCARD_H

#include <unistd.h>
#include "esp_vfs_fat.h"
#include "driver/sdspi_host.h"
#include "driver/spi_common.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"

/* 引脚定义 */
/* SPI管脚 */
#define SPI_SCLK_PIN        GPIO_NUM_12
#define SPI_MOSI_PIN        GPIO_NUM_11
#define SPI_MISO_PIN        GPIO_NUM_13
/* 总线设备引脚定义 */
#define SD_CS_PIN           GPIO_NUM_2

/* SPI端口 */
#define MY_SPI_HOST         SPI2_HOST

#define SD_NUM_CS           GPIO_NUM_2
#define MOUNT_POINT         "/0:"

/* 设备句柄 */
extern spi_device_handle_t MY_SD_Handle;   /* SD卡句柄 */
extern sdmmc_card_t *card;      /* SD / MMC卡结构 */

/* 函数声明 */
esp_err_t spi_init(void);       /* SPI初始化 */
esp_err_t sd_init(void);        /* SD卡初始化 */
void sd_get_fatfs_usage(size_t *out_total_bytes, size_t *out_free_bytes);

#endif
